/**
 * Created by mac on 2018/8/30.
 */
import { ADD_ITEM , CHANGE_INPUT_VALUE, DELETE_ITEM } from './actionTypes';

const defaultState = {
    list: [],
    inputValue: '12'
}

export default (state = defaultState, action) => {
    const newState = JSON.parse(JSON.stringify(state));
    if (action.type === CHANGE_INPUT_VALUE) {
        newState.inputValue = action.value;
        return newState;
    }

    if (action.type === ADD_ITEM) {
        newState.list.push(newState.inputValue);
        newState.inputValue = '';
        return newState;
    }

    if (action.type === DELETE_ITEM) {
        newState.list.splice(action.value, 1);
        return newState;
    }
    return state;
}